package com.sky.controller.user;

import com.sky.dto.ShoppingCartDTO;
import com.sky.entity.ShoppingCart;
import com.sky.result.Result;
import com.sky.service.ShoppingCartService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 功能简述:
 *
 * @author 86156
 * @date: 2024/09/09
 */
@RestController
@RequestMapping("/user/shoppingCart")
@Slf4j
public class ShoppingCartController {
    @Autowired
    private ShoppingCartService shoppingCartService;
    /**
     * 添加到购物车
     * @return
     */
    @PostMapping("/add")
    public Result addToShoppingCart(@RequestBody ShoppingCartDTO shoppingCartDTO) {
        log.info("添加到购物车：{}", shoppingCartDTO);
        shoppingCartService.addToShoppingCart(shoppingCartDTO);
        return Result.success();
    }
    @GetMapping("/list")
    public Result<List<ShoppingCart>> list() {
        log.info("查询购物车");
        return Result.success(shoppingCartService.list());
    }
    @PostMapping("/sub")
    public Result removeFromShoppingCart(@RequestBody ShoppingCartDTO shoppingCartDTO) {
        log.info("清空购物车");
        shoppingCartService.removeFromShoppingCart(shoppingCartDTO);
        return Result.success();
    }
    @DeleteMapping("/clean")
    public Result clean(){
        log.info("清空购物车");
        shoppingCartService.clean();
        return Result.success();
    }
}
